<!DOCTYPE html>
<html  xmlns:th="http://www.thymeleaf.org">

<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>新增学生页面</title>
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <th:block th:replace="/common_resources::common_css"></th:block>
    <th:block th:replace="/common_resources::common_js"></th:block>
</head>

<body class="hold-transition skin-purple sidebar-mini">

<header th:replace="~{/common_header::header}"></header>
<aside th:replace="/common_aside::aside"></aside>

<div class="wrapper">


    <!-- 内容区域 -->
    <!-- @@master = admin-layout.html-->
    <!-- @@block = content -->

    <div class="content-wrapper">

        <!-- 内容头部 -->
        <section class="content-header">
            <h1>
                学生信息管理
                <small>学生信息</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="/index"><i class="fa fa-dashboard"></i> 首页</a></li>
                <li><a href="/student/all">学生信息管理</a></li>
                <li class="active">学生信息</li>
            </ol>
        </section>
        <!-- 内容头部 /-->

        <!-- 正文区域 -->
        <section class="content">

            <div class="box-body">

                <!--tab页-->
                <div class="nav-tabs-custom">

                    <!--tab内容-->
                    <div class="tab-content">

                        <form >
                            <!--基础控件-->

                            <div class="tab-pane" id="tab-common">

                                <div class="row data-type">

                                    <div class="col-md-2 title">学号</div>
                                    <div class="col-md-4 data">
                                        <input type="text" class="form-control" placeholder="学号" name="username" id="username"  value="">
                                    </div>

                                    <div class="col-md-2 title">名字</div>
                                    <div class="col-md-4 data">
                                        <input type="text" class="form-control" placeholder="名字" name="name" id="name" value="">
                                    </div>

                                    <div class="col-md-2 title">性别</div>
                                    <div class="col-md-4 data">
                                        <select class="form-control" name="sex" id="sex">
                                            <option>男</option>
                                            <option>女</option>

                                        </select>
                                    </div>

                                    <div class="col-md-2 title">电话</div>
                                    <div class="col-md-4 data">
                                        <div class="input-group">
                                            <input type="text" class="form-control" placeholder="电话" name="phoneNumber" id="phoneNumber">

                                        </div>
                                    </div>
                                    <div class="col-md-2 title">生日</div>
                                    <div class="col-md-4 data">
                                        <div class="input-group">
                                            <input type="date" class="form-control" placeholder="生日" name="birthday" id="birthday">

                                        </div>
                                    </div>

                                    <div class="col-md-2 title">班级</div>
                                    <div class="col-md-4 data">
                                        <select class="form-control select2" name="className" id="className"  style="width: 100%;">

                                            <option th:each="class:${classList}"  th:text="${class.className}"></option>
                                        </select>
                                    </div>


                                    <div class="col-md-2 title"></div>
                                    <div class="col-md-10 data text-center">
                                        <button type="button" class="btn bg-maroon" id="submit">保存</button>
                                        <button type="button" class="btn bg-default" onclick="history.back(-1);">返回</button>
                                    </div>

                                </div>
                            </div>
                            <!--基础控件/-->
                        </form>


                    </div>
                    <!--tab内容/-->

                </div>
                <!--tab页/-->



            </div>

        </section>
        <!-- 正文区域 /-->

    </div>
    <!-- @@close -->
    <!-- 内容区域 /-->


</div>
<script>
    $(function () {
        $("#submit").click(function (){
            console.log("OK")
            addStudent();
        });
    });
    function addStudent() {

        var username=$("#username").val();
        var name=$("#name").val();
        var sex=$("#sex").val();
        var phoneNumber=$("#phoneNumber").val();
        var birthday=$("#birthday").val().toString();
        var className=$("#className").val();
        var data={
            username:username,
            name:name,
            sex:sex,
            phoneNumber:phoneNumber,
            birthday:birthday,
            className:className
        };
        $.post("/student/add", data,function (result){
            if (result=="添加失败"){
                alert("添加失败,学号已存在");
                location.href="/class/all";

            }else {

                alert("添加成功");
                location.href="/student/all";
            }



        })
    }

</script>

<footer th:replace="~{/common_footer::footer}"></footer>

</body>

</html>